package cn.kfm666.data.structure.sort;

import cn.kfm666.data.structure.util.GenerateData;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

/**
 * 冒泡排序
 */
public class BubbleSort {

    public static void main(String[] args){
        BubbleSort sort = new BubbleSort();
        Scanner scanner = new Scanner(System.in);
        System.out.println("please input data size:");
        int size = scanner.nextInt();
        int[] data = GenerateData.generateIntArray(size,100000);
        System.out.println("初始数据："+Arrays.toString(data));
        Long start = System.currentTimeMillis();
        sort.sort(data,size);
        Long end = System.currentTimeMillis();
        System.out.println("排序数据："+Arrays.toString(data));
        System.out.println("用时："+(end-start)+"毫秒");
    }

    public void sort(int[] data,int size){
        int count = 0;
        for (int i=0;i<data.length-1;i++){
            for (int j=i+1;j<data.length;j++){
                if (data[i]>data[j]){
                    int temp = data[i];
                    data[i] = data[j];
                    data[j] = temp;
                    count++;
                }
            }
        }

    }
}
